package com.example.zhuyu.basemvp.http;

import com.example.zhuyu.basemvp.utils.PrintNetLog;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;


public class NetWorkInterceptor implements Interceptor {


    public NetWorkInterceptor() {
    }

    @Override
    public Response intercept(Chain chain) throws IOException {

        Request request = chain.request();
        /**
         * 判断请求方式及拼接请求参数等操作
         */
        Request.Builder builder = request.newBuilder();

        Response response = chain.proceed(request);
        printLog(response,request);

        return response;
    }

    /**
     * 打印请求和返回的日志
     */
    private void printLog(Response response, Request request) {
        PrintNetLog printNetLog = new PrintNetLog();
        //打印请求URL
        printNetLog.printRequestUrl(request);
        //打印拼接后参数
        printNetLog.printParamsAfter(request);
        //打印服务器返回数据
        printNetLog.printServerResult(response);
    }
}
